package action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.LookupDispatchAction;

import form.LoginForm;

import utilidades.Constants;
import vo.UsuarioVO;

import bo.UsuarioBO;

public class LoginAction extends LookupDispatchAction{

	public ActionForward newSearch(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		return mapping.findForward("success");
	}

	public ActionForward aceptar(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		final String tmpNick = ((LoginForm)form).getIdUsuario();
		UsuarioBO tmpUsuarioBo = new UsuarioBO();
		final UsuarioVO tmpUsuario = (UsuarioVO) tmpUsuarioBo.load(new UsuarioVO(tmpNick));
		request.getSession().setAttribute(Constants.USUARIO_ACTUAL, tmpUsuario);
		return mapping.findForward("datosUsuario");
	}
	
	public ActionForward limpiar(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		return mapping.findForward("success");
	}

	@Override
	protected Map getKeyMethodMap() {
		// TODO Auto-generated method stub
		Map map=new HashMap();
		map.put("login.aceptar","aceptar");
		map.put("login.limpiar","limpiar");
		map.put("action.newSearch","newSearch");
		
		return map;
	}


}
